import request from '@/config/axios'

// 供应商联系人 VO
export interface SupplierContactsVO {
  id: number // id
  supplierId: number // 供应商ID
  name: string // 姓名
  sex: string // 性别(字典值：男/女/未知)
  position: string // 职务
  email: string // 邮箱
  landline: string // 座机
  phone: string // 移动电话
  facebook: string // Facebook
  ins: string // ins
  tiktok: string // tiktok
  youtube: string // Youtube
  linkedin: string // Linkedin
  remark: string // 备注
}

// 供应商联系人 API
export const SupplierContactsApi = {
  // 查询供应商联系人分页
  getSupplierContactsPage: async (params: any) => {
    return await request.get({ url: `/business/supplier-contacts/page`, params })
  },

  // 查询供应商联系人详情
  getSupplierContacts: async (id: number) => {
    return await request.get({ url: `/business/supplier-contacts/get?id=` + id })
  },

  // 新增供应商联系人
  createSupplierContacts: async (data: SupplierContactsVO) => {
    return await request.post({ url: `/business/supplier-contacts/create`, data })
  },

  // 修改供应商联系人
  updateSupplierContacts: async (data: SupplierContactsVO) => {
    return await request.put({ url: `/business/supplier-contacts/update`, data })
  },

  // 删除供应商联系人
  deleteSupplierContacts: async (id: number) => {
    return await request.delete({ url: `/business/supplier-contacts/delete?id=` + id })
  },

  // 导出供应商联系人 Excel
  exportSupplierContacts: async (params) => {
    return await request.download({ url: `/business/supplier-contacts/export-excel`, params })
  },

  // 根据供应商ID获取联系人列表
  getSupplierContactsBySupplierId: async (supplierId: number) => {
      try {
        const data = await request.get({ 
          url: `/business/supplier-info/get-list`,
          params: { supplier_id: supplierId }
        });
        return {
          success: true,
          data: data
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : '获取联系人列表失败'
        };
      }
  }
}
